package com.allen.study.domain.utils.security;

import com.allen.study.domain.entity.EmployeeLogin;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @ClassName: MySysUserDetails
 * @Author: AllenSun
 * @Date: 2025/3/6 22:13
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MySysUserDetails implements UserDetails {
    private Integer id;
    private String username;
    private String password;
    private String token;

    // 用户拥有的权限集合，我这里先设置为null，将来会再更改的
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    public MySysUserDetails(EmployeeLogin employeeLogin) {
        // this.id = employeeLogin.getId();
        this.username = employeeLogin.getEmployeeId();
        this.password = employeeLogin.getEncryptedPassword();
        this.token = employeeLogin.getToken();
    }

    //    后面四个方法都是用户是否可用、是否过期之类的。我都设置为true
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
